package com.amado.course36ByteStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 字节流读取文件信息
 * 
 * @author Administrator
 *
 */
public class S03FileInputStreamWhile {
	public static void main(String[] args) throws IOException {
		File file = new File("D:\\Hello2.java");
		// 字节流输入对象，输入流
		FileInputStream inputStream = new FileInputStream(file);
		byte[] byteArray = new byte[20];
		try {
			//length 返回的整数表示读取的字节数，如果遇到输入流的结尾，返回-1
			int length = 0;
			while ((length = inputStream.read(byteArray)) != -1) {
//				System.out.println("length:"+length);
//				System.out.println(new String(byteArray)+"a");
//				System.out.println(new String(byteArray,0,length)+"a");
				System.out.print(new String(byteArray,0,length));
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			inputStream.close();
		}
	}
}
